<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>递归地合并一个或多个数组</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.array-merge-recursive" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_merge_recursive</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.0.1, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">array_merge_recursive</span> &mdash; <span class="dc-title">递归地合并一个或多个数组</span></p>

   </div>
   
 <div class="refsect1 description" id="refsect1-function.array-merge-recursive-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_merge_recursive</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array1</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$...</code></span>
  ] ) : <span class="type">array</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_merge_recursive()</strong></span> 将一个或多个数组的单元合并起来，一个数组中的值附加在前一个数组的后面。返回作为结果的数组。
    </p>
    <p class="para">
     如果输入的数组中有相同的字符串键名，则这些值会被合并到一个数组中去，这将递归下去，因此如果一个值本身是一个数组，本函数将按照相应的条目把它合并为另一个数组。需要注意的是，如果数组具有相同的数值键名，后一个值将不会覆盖原来的值，而是附加到后面。
    </p>
   </div>

   
    <div class="refsect1 parameters" id="refsect1-function.array-merge-recursive-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">array1</code></dt>

     <dd>

      <p class="para">
       要合并的初始数组。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">...</code></dt>

     <dd>

      <p class="para">
       数组变量列表，进行递归合并。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

   
    <div class="refsect1 returnvalues" id="refsect1-function.array-merge-recursive-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   一个结果数组，其中的值合并自附加的参数。
  </p>
 </div>

   
    <div class="refsect1 examples" id="refsect1-function.array-merge-recursive-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-6046">
    <p><strong>Example #1 <span class="function"><strong>array_merge_recursive()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$ar1&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"color"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(</span><span style="color: #DD0000">"favorite"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"red"</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$ar2&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"color"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(</span><span style="color: #DD0000">"favorite"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"green"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"blue"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_merge_recursive</span><span style="color: #007700">(</span><span style="color: #0000BB">$ar1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ar2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [color] =&gt; Array
        (
            [favorite] =&gt; Array
                (
                    [0] =&gt; red
                    [1] =&gt; green
                )

            [0] =&gt; blue
        )

    [0] =&gt; 5
    [1] =&gt; 10
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-merge-recursive-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="array_merge.html" class="function" rel="rdfs-seeAlso">array_merge()</a> - 合并一个或多个数组</span></li>
    <li class="member"><span class="function"><a href="array_replace_recursive.html" class="function" rel="rdfs-seeAlso">array_replace_recursive()</a> - 使用传递的数组递归替换第一个数组的元素</span></li>
   </ul>
  </p>
 </div>

   
  </div></div></div></body></html>